# 定时任务

from celery import shared_task

import asyncio

from test_queue import MysqlDb

# 异步任务

async def consume(*args):
    mydb = MysqlDb()

    # if len(args[0]) == 1:
    #     for i in range(3):
    #         newa = '(' + str(args[0][0]) + ')'
    #         sql += "select * from order_%s where now() > adddate(date,interval 1 day) and state in (1,0) " % (i + 1)
    #         if args is not None:
    #             sql += "and orderid in %s " % newa
    #         sql += "union "
    # if len(args[0]) > 1:
    #     for i in range(3):
    #         sql += "select * from order_%s where now() > adddate(date,interval 1 day) and state in (1,0) " % (i + 1)
    #         if args is not None:
    #             sql += "and orderid in %s " % str(args[0])
    #         sql += "union "
    # sql = sql.rstrip("union ")

    for i in range(3):
        sql = "delete from order_%s where now() > adddate(date,interval 24 hour) and `state` in (0,1)" % (i+1)
        if len(args[0]) == 1:
            sql += "and orderid in %s " % '(' + str(args[0][0]) + ')'
        if len(args[0]) > 1:
            sql += "and orderid in %s " % str(args[0])
        mydb.update(sql)

    return '删除ok'


# @shared_task
# def async_consume(*args):
#     return asyncio.run(consume(args))
